package com.efun.edata;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

/**
 * Created by kinven on 18-3-7.
 */
public class SimpleApp {
    public static void main(String[] args) {
        String logFile = "hdfs://ehdp-node-5:8020/examples/README.md"; // Should be some file on your system
        SparkConf conf = new SparkConf().setAppName("Siample Application");
        JavaSparkContext sc = new JavaSparkContext(conf);
        JavaRDD<String> logData = sc.textFile(logFile).cache();
//        SparkSession spark = SparkSession.builder().appName("Simple Application").getOrCreate();
//        Dataset<String> logData = spark.read().textFile(logFile).cache();

        long numAs = logData.filter(s -> s.contains("hello")).count();
        long numBs = logData.filter(s -> s.contains("world")).count();

        System.out.println("Lines with hello: " + numAs + ", lines with world: " + numBs);

        sc.stop();
    }
}
